home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / frontend / lametime.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-24  |  3.4 KB  |  157 lines

  1. /*
  2.  *    Lame time routines source file
  3.  *
  4.  *    Copyright (c) 2000 Mark Taylor
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the
  18.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.  * Boston, MA 02111-1307, USA.
  20.  */
  21.  
  22. /* $Id: lametime.c,v 1.12 2001/06/23 17:56:10 robert Exp $ */
  23.  
  24. /*
  25.  * name:        GetCPUTime ( void )
  26.  *
  27.  * description: returns CPU time used by the process
  28.  * input:       none
  29.  * output:      time in seconds
  30.  * known bugs:  may not work in SMP and RPC
  31.  * conforming:  ANSI C
  32.  *
  33.  * There is some old difficult to read code at the end of this file.
  34.  * Can someone integrate this into this function (if useful)?
  35.  */
  36.  
  37. #ifdef HAVE_CONFIG_H
  38. # include <config.h>
  39. #endif
  40.  
  41. #include <assert.h>
  42. #include <stdio.h>
  43. #include <time.h>
  44.  
  45. #ifdef WITH_DMALLOC
  46. #include <dmalloc.h>
  47. #endif
  48.  
  49. #include "lametime.h"
  50.  
  51.  
  52. double GetCPUTime ( void )
  53. {
  54.     clock_t  t;
  55.  
  56. #if defined(_MSC_VER)  ||  defined(__BORLANDC__)    
  57.     t = clock ();
  58. #else
  59.     t = clock ();
  60. #endif    
  61.     return t / (double) CLOCKS_PER_SEC;
  62. }
  63.  
  64.  
  65. /*
  66.  * name:        GetRealTime ( void )
  67.  *
  68.  * description: returns real (human) time elapsed relative to a fixed time (mostly 1970-01-01 00:00:00)
  69.  * input:       none
  70.  * output:      time in seconds
  71.  * known bugs:  bad precision with time()
  72.  */
  73.  
  74. #if defined(__unix__)  ||  defined(SVR4)  ||  defined(BSD)
  75.  
  76. # include <sys/time.h>
  77. # include <unistd.h>
  78.  
  79. double GetRealTime ( void )            /* conforming:  SVr4, BSD 4.3 */
  80. {
  81.     struct timeval  t;
  82.  
  83.     if ( 0 != gettimeofday (&t, NULL) )
  84.         assert (0);
  85.     return t.tv_sec + 1.e-6 * t.tv_usec;
  86.  
  87. #elif defined(WIN16)  ||  defined(WIN32)
  88.  
  89. # include <stdio.h>
  90. # include <sys/types.h>
  91. # include <sys/timeb.h>
  92.  
  93. double GetRealTime ( void )            /* conforming:  Win 95, Win NT */
  94. {
  95.     struct timeb  t;
  96.     
  97.     ftime ( &t );
  98.     return t.time + 1.e-3 * t.millitm;
  99. }
  100.  
  101. #else
  102.  
  103. double GetRealTime ( void )            /* conforming:  SVr4, SVID, POSIX, X/OPEN, BSD 4.3 */
  104. {                        /* BUT NOT GUARANTEED BY ANSI */
  105.     time_t  t;
  106.     
  107.     t = time (NULL);
  108.     return (double) t;
  109.  
  110. #endif
  111.                               
  112.  
  113. #if defined(_WIN32) || defined(__CYGWIN__)
  114. # include <io.h>
  115. # include <fcntl.h>
  116. #else
  117. # include <unistd.h>
  118. #endif
  119.  
  120. int  lame_set_stream_binary_mode ( FILE* const fp )
  121. {
  122. #if   defined __EMX__
  123.     _fsetmode ( fp, "b" );
  124. #elif defined __BORLANDC__
  125.     setmode   (_fileno(fp),  O_BINARY );
  126. #elif defined __CYGWIN__
  127.     setmode   ( fileno(fp), _O_BINARY );
  128. #elif defined _WIN32
  129.     _setmode  (_fileno(fp), _O_BINARY );
  130. #endif
  131.     return 0;
  132. }
  133.  
  134.  
  135. #if defined(__riscos__)
  136. # include <kernel.h>
  137. # include <sys/swis.h>
  138. #elif defined(_WIN32)
  139. # include <sys/types.h>
  140. # include <sys/stat.h>
  141. #else
  142. # include <sys/stat.h>
  143. #endif
  144.  
  145. off_t  lame_get_file_size ( const char* const filename )
  146. {
  147.     struct stat       sb;
  148.  
  149.     if ( 0 == stat ( filename, &sb ) )
  150.         return sb.st_size;
  151.     return (off_t) -1;
  152. }
  153.  
  154. /* End of lametime.c */
  155.